package com.ovstech.samples.axon.file;

import com.ovstech.samples.axon.file.command.CreateFileNodeCommand;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private CommandGateway commandGateway;


    @PostMapping("")
    @ResponseStatus(HttpStatus.CREATED)
    public Object create(@RequestParam("name") String name,
                         @RequestParam("size") Long size) {
        commandGateway.send(new CreateFileNodeCommand(UUID.randomUUID().toString(), name, size));

        return "success";
    }
}
